package com.woniuxy.order.service.impl;

//import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.rabbitmq.client.Channel;
import com.woniuxy.order.entity.RenthouseOrder;
import com.woniuxy.order.mapper.RenthouseOrderMapper;
import com.woniuxy.order.service.RenthouseOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.order.util.OrderNumberCreator;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;
import java.time.LocalDateTime;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author maotao
 * @since 2021-03-19
 */
@Service
public class RenthouseOrderServiceImpl extends ServiceImpl<RenthouseOrderMapper, RenthouseOrder> implements RenthouseOrderService {

    @Autowired
    RenthouseOrderMapper renthouseOrderMapper;


    @RabbitListener(queues = "topic.rent")
    public void addOrder(RenthouseOrder order,Channel channel,Message message) throws IOException {
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        String serverOrderNum = OrderNumberCreator.createServerOrderNum();
        order.setOrderno(serverOrderNum)
                .setStatus(0)
                .setTime(LocalDateTime.now());
        renthouseOrderMapper.insert(order);
    }

    @Override
//    @SentinelResource("test")
    public String test() {
        return "链路模式测试";
    }


}
